var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/help/CustomerHelp.tsx
var CustomerHelp_exports = {};
__export(CustomerHelp_exports, {
  CustomerHelp: () => CustomerHelp
});
module.exports = __toCommonJS(CustomerHelp_exports);
var import_react = __toESM(require("react"));
var import_baseComponent = require("../../baseComponent");
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../functionalComponent/table/util");
var import_util2 = require("../../util");
var tableProps = {
  cache: false,
  headerMenu: false,
  style: { borderStyle: "solid", borderColor: "var(--border-color-split, #f0f0f0)", borderWidth: 1 }
};
var { Header, Footer, MultipleButtons } = import_functionalComponent.BaseHelp;
var defaultColumns = [
  {
    dataIndex: "code",
    title: "客户编码",
    flex: 1,
    tooltip: true
  },
  {
    dataIndex: "name",
    title: "客户名称",
    flex: 3,
    width: 150,
    tooltip: true
  },
  {
    dataIndex: "typeName",
    title: "客户类型",
    flex: 1,
    tooltip: true
  },
  {
    dataIndex: "groupCodeName",
    title: "所属集团单位",
    flex: 3,
    tooltip: true
  },
  {
    dataIndex: "unifiedSocialCode",
    title: "统一社会信用代码",
    flex: 3,
    width: 150,
    tooltip: true
  },
  {
    dataIndex: "corporation",
    title: "法人",
    flex: 1,
    tooltip: true
  }
];
function HelpContent() {
  const {
    request,
    ok,
    contentParams: { getFieldValue, columns, helpTitle, helpId, selectedArray, multiple, footer },
    locale,
    randomKey
  } = (0, import_react.useContext)(import_functionalComponent.HelpContext);
  const btnRef = (0, import_react.useRef)();
  const rightTable = (0, import_react.useRef)();
  const getTable = () => import_util2.iup.compIns[`${helpId}_${randomKey}`].getApi();
  const onSearch = (value) => {
    getTable().query({ keyword: value });
  };
  const toRight = (values) => {
    if (multiple) {
      btnRef.current.toRight(values);
    } else {
      ok(getResult());
    }
  };
  const getResult = () => {
    if (multiple) {
      const result = rightTable.current.getApi().getRows().map((r) => ({
        value: getFieldValue(r),
        label: getFieldValue(r, "label"),
        origin: { ...r }
      }));
      return result.length > 0 ? result : void 0;
    } else {
      const value = getTable().getSelectedData()[0];
      if (value) {
        return { value: getFieldValue(value), label: getFieldValue(value, "label"), origin: { ...value } };
      }
      return void 0;
    }
  };
  tableProps.checkbox = multiple ? "checked" : false;
  tableProps.rowSelected = !multiple;
  tableProps.rowChecked = multiple;
  return /* @__PURE__ */ import_react.default.createElement(import_util2.Layout, null, /* @__PURE__ */ import_react.default.createElement(Header, { title: helpTitle }), /* @__PURE__ */ import_react.default.createElement(import_util2.Layout.Flex, { direction: "row", style: { padding: "0 5px" } }, /* @__PURE__ */ import_react.default.createElement(import_util2.Layout.Flex, { flex: 4, direction: "column", style: { paddingTop: 7, paddingBottom: 32 } }, /* @__PURE__ */ import_react.default.createElement(
    import_baseComponent.Search,
    {
      size: "small",
      onSearch,
      allowClear: true,
      placeholder: locale.searchPlaceholder,
      style: { paddingBottom: 7, width: 220, alignSelf: "flex-end" }
    }
  ), /* @__PURE__ */ import_react.default.createElement(import_util2.Layout.Flex, null, /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.Table,
    {
      id: `${helpId}_${randomKey}`,
      ...tableProps,
      columns,
      request,
      pagination: {
        height: 32,
        showQuickJumper: false,
        align: "left",
        targetContainer: `${helpId}_${randomKey}_pagination`
      },
      onRow: (rowIndex, table) => ({
        onDoubleClick: () => toRight([table.getRow(rowIndex)])
      })
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      id: `${helpId}_${randomKey}_pagination`,
      style: {
        position: "absolute",
        display: "block",
        left: 15,
        right: 15,
        paddingLeft: 10
      }
    }
  ))), multiple && /* @__PURE__ */ import_react.default.createElement(
    MultipleButtons,
    {
      getRowKey: getFieldValue,
      outRef: btnRef,
      getActiveTable: getTable,
      getResultTable: () => rightTable.current.getApi()
    }
  ), multiple && /* @__PURE__ */ import_react.default.createElement(import_util2.Layout.Flex, { flex: 3, style: { paddingTop: 7, paddingBottom: 32 } }, /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.Table,
    {
      ...tableProps,
      columns,
      dataSource: selectedArray,
      ref: rightTable,
      onRow: (rowIndex) => ({
        onDoubleClick: () => btnRef.current.toLeft(rowIndex)
      })
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      id: `${helpId}_${randomKey}_pagination`,
      style: {
        position: "absolute",
        right: 15,
        paddingLeft: 10
      }
    }
  ))), /* @__PURE__ */ import_react.default.createElement(Footer, { getResult }, footer && /* @__PURE__ */ import_react.default.createElement("span", { children: footer })));
}
var CustomerHelp = (0, import_util.compHoc)((props) => {
  const {
    valueField = "code",
    labelField = "name",
    displayField,
    userCodeField,
    title,
    multiple = false,
    modalProps,
    onBeforeOpen,
    footer,
    customerBusinessRequest,
    customerBusinessParams = {},
    codeList = [],
    columns,
    ...others
  } = props;
  const helpId = "customer";
  const otherProps = others;
  otherProps.onBeforeOpen = (0, import_util2.useRefCallback)(async () => {
    if (onBeforeOpen) {
      const canOpen = await onBeforeOpen();
      if (canOpen === false) {
        return false;
      }
    }
    return {};
  });
  otherProps.request = (0, import_util2.useRefCallback)(async ({ pageIndex, pageSize, keyword }) => {
    const data = {
      ...customerBusinessParams,
      pageNum: pageIndex,
      pageSize,
      codeList
    };
    keyword && (data.searchStr = keyword.trim());
    if (customerBusinessRequest) {
      return await customerBusinessRequest(data);
    }
    const res = await import_util2.iup.request.body({
      // basedata/cussup/searchByType
      url: "/basedata/cussup/searchByType",
      data
    });
    if ((res == null ? void 0 : res.code) === 0)
      return res == null ? void 0 : res.data;
    return { list: [], total: 0 };
  });
  otherProps.valueField = valueField;
  otherProps.userCodeField = userCodeField;
  otherProps.labelField = labelField || displayField;
  otherProps.contentParams = {
    footer,
    helpId,
    multiple,
    valueField,
    labelField: otherProps.labelField,
    columns: columns ?? defaultColumns
  };
  otherProps.contentParams.helpTitle = title || "客户帮助";
  otherProps.selectedRequest = (0, import_util2.useRefCallback)(async ({ codes }) => {
    try {
      const { code, data } = await import_util2.iup.request.body({
        url: "/basedata/cussup/listByTypeAndCodes",
        skipError: true,
        data: { codeList: codes.split(",") }
      });
      return code === 0 ? data : [];
    } catch (e) {
    }
    return [];
  });
  const { height } = (0, import_util2.getGlobalConfig)().default.helpConfig;
  const width = multiple ? 1700 : 1200;
  return /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.BaseHelp,
    {
      ...otherProps,
      input: false,
      modal: true,
      helpContent: HelpContent,
      multiple,
      modalProps: { width, height, ...modalProps }
    }
  );
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  CustomerHelp
});
